<template>
	<view class="container flex-c">
		<uni-nav-bar class="ch-nav" height="88rpx" backgroundColor="#ffffff" leftWidth="90rpx" rightWidth="90rpx" color="#333" :fixed="true" :padding="false" :border="false" @clickLeft="$goBack(1)">
			<template slot="left">
				<image class="left" src="@/public/images/public/dhl_fhjt.png" mode="aspectFit"></image>
			</template>
			<text class="title">设置</text>
		</uni-nav-bar>
		<view class="body flex-c">
			<view class="list">
				<view class="list-item flex-r" @tap="$goByName('usercomments')">
					<view class="item-title">
						我的留言
					</view>
					<view class="item-arrow flex-r">
						<uni-icons type="right" color="#999999" size="38rpx"></uni-icons>
					</view>
				</view>
			</view>
			<view class="list">
				<view class="list-item flex-r" @tap="$goByName('editpassword')">
					<view class="item-title">
						修改登录密码
					</view>
					<view class="item-arrow flex-r">
						<uni-icons type="right" color="#999999" size="38rpx"></uni-icons>
					</view>
				</view>
				<view class="list-item flex-r" @tap="editPhone">
					<view class="item-title">
						修改手机号
					</view>
					<view class="item-arrow flex-r">
						<text class="status" v-if="phone">{{hidePhone(phone)}}</text>
						<uni-icons type="right" color="#999999" size="38rpx"></uni-icons>
					</view>
				</view>
			</view>
			<view class="list">
				<view class="list-item flex-r" @tap="$goByName('aboutus')">
					<view class="item-title">
						关于我们
					</view>
					<view class="item-arrow flex-r">
						<uni-icons type="right" color="#999999" size="38rpx"></uni-icons>
					</view>
				</view>
			</view>
		</view>
		<view class="foot bottom-ios">
			<view class="submit-box">
				<button type="default" class="active" @tap="logout">退出登录</button>
			</view>
		</view>
	</view>
</template>

<script>
	import imMsg from "@/utils/common/message.js";
	export default {
		data() {
			return {
				code: null,
				phone: null
			}
		},
		computed: {
			user() {
				return this.$store.state.user
			},
			weixin(){
				return this.$store.state.weixin
			}
		},
		onLoad() {
			//拦截微信code
			if(this.$Route.query.code){
				this.code = this.$Route.query.code
				console.log(this.code)
				this.bindWeixin()
			}
			this.phone = uni.getStorageSync('user_phone') || null
		},
		updated() {
			console.log(this.weixin,'this.weixin')
		},
		methods: {
			editPhone() {
				uni.showToast({
					title: '暂不支持',
					icon: 'none'
				})
			},
			//手机号隐藏部分信息
			hidePhone(phone){
				return phone.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2")
			},
			/* //绑定微信
			bindWeixin() {
				this.$http.get({
					url: '/api/oauth/weChatAuthByWeb/' + this.code,
					data: {
						code: this.code
					},
				}).then((data) => {
					console.log(data);
				}).catch((err) => {
					console.log(err);
				})
			},
			//获取code
			getWeixinCode() {
				if(this.isWeixin()){
					//跳转打开code链接
					let redirect_url = window.location.href + '?wxcode=1'
					let scope = 'snsapi_userinfo'
					let url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+this.$CHS.config.wxAppId+"&redirect_uri="+ encodeURIComponent(redirect_url) + "&response_type=code&scope="+scope+"&state=wxlogin#wechat_redirect"
					window.location.href = url
					//跳转打开code链接
				}else{
					uni.showModal({
						title: '系统提示',
						content: '请先在微信客户端内打开当前页面，然后进行微信绑定操作',
						showCancel: false
					})
				}
			}, */
			//退出登录
			logout(){
				uni.showModal({
					title:'退出登录',
					content: '确认要退出登录吗？',
					confirmText: '确认',
					confirmColor: '#0055FF',
					success: (res) => {
						if(res.confirm){
							this.$store.dispatch('logOut').then(data => {
								this.$ShowToast({text: '已退出登录', type: 1})
								//清除跳转缓存
								sessionStorage.removeItem('redirectTo')
								//清除邀请码
								sessionStorage.removeItem('inviteCode')
								sessionStorage.removeItem('inviteType')
								sessionStorage.removeItem('specialCode')
								//清除其他缓存
								uni.removeStorageSync('apply_expert')
								setTimeout(()=>{
									//同步退出im
									if(this.$store.state.imReady){
										imMsg.logout()
									}
									this.$store.commit('RESET_STATE')
									//跳转我的
									this.$goByName('userhome')
									//重置store
								}, 1000)
							}).catch((err) => {
								console.log(err);
								if(err.statusCode !== 401){
									uni.showToast({
										title: '网络请求异常，请重试',
										icon: 'none'
									})
								}
							})
						}
					}
				})
			},
			//判断浏览器类型
			isWeixin() {
				let ua = navigator.userAgent.toLowerCase();
				if (ua.match(/micromessenger/i) == "micromessenger"){
					console.log(1);
					store.commit("IS_WEIXIN",true)
					// return true
				}else{
					console.log(2);
					store.commit("IS_WEIXIN",false)
					// return false
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.body{
		margin-top: 20rpx;
		.list{
			margin-bottom: 20rpx;
			background-color: #FFFFFF;
			.list-item{
				padding: 0 20rpx;
				align-items: center;
				height: 96rpx;
				border-bottom: 1rpx solid #EDEDED;
				.item-title{
					flex: 2;
					font-size: 30rpx;
				}
				.item-arrow{
					align-items: center;
					.status{
						color: #999999;
						font-size: 28rpx;
						margin-right: 10rpx;
					}
				}
			}
			.list-item:last-child{
				border: none;
			}
		}
	}
	.foot{
		.submit-box{
			margin: 20rpx
		}
	}
</style>
